package com.dily.study.demo.config.websocket.first;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.HandshakeInterceptor;

import javax.annotation.Resource;

/**
 * Date: 2022-04-28 星期四
 * Time: 14:37
 * Author: Dily_Su
 * Remark: 方式一
 */
//@Configuration
//@EnableWebSocket
public class WebSocketConfiguration implements WebSocketConfigurer {
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(new DefaultHandler(), "/ws") // api  对应controller
                .addInterceptors(new DefaultInterceptor()) // 拦截器
                .setAllowedOrigins("*");
    }
}
